package com.explorati.LeetCode011.containerwithmostwater;

/**
 * 11. Container With Most Water 双指针
 * 
 * Input: [1,8,6,2,5,4,8,3,7] Output: 49
 * 
 * @author explorati
 *
 */
public class Solution {
	public static int maxArea(int[] height) {
		if (height.length <= 1) {
			return 0;
		}

		// 一个指向左边最大元素，一个指向右侧最大元素
		int i = 0, j = height.length - 1;
		int maxArea = 0, temp = 0;
		// int maxArea = Math.min(height[i], height[j]) * (j - i);
		while (i < j) {
			if (height[i] > height[j]) {
				temp = (j - i) * height[j];
				j--;
			} else {
				temp = (j - i) * height[i];
				i++;
			}
			maxArea = maxArea > temp ? maxArea : temp;

		}
		return maxArea;
	}

	public static void main(String[] args) {
		int[] height = { 2, 3, 4, 5, 18, 17, 6 };
		System.out.println(maxArea(height));
	}
}
